Welcome to ‘Microservices Patterns’. After watching this video, you will be able to describe patterns you can use with microservices,
and explain the usage of different patterns. Microservices have numerous patterns
available that enable some of the more common challenges and opportunities. Examples are the single-page application (or SPA) pattern, the Backend for Frontend (or BFF) pattern, the Strangler pattern, and the service discovery pattern. With the convergence of more powerful browsers,
faster networks, and client-side languages, many web interfaces began incorporating all
functionality into single-page applications. The user enters through one interface
that never reloads the landing page or navigates away from the initial experience. Built using a combination of HTML, CSS,
and JavaScript, these applications respond to user input through dynamic service
calls to backend REST-based services that update portions of the screen instead
of redirecting to an entirely new page. This application architecture often
simplifies the front-end experience, with the tradeoff of more
responsibility on the backend services. While a single-page application works
well for single-channel user experiences, it delivers poor results across user experiences
through different channels, like mobile and web. A Backend for Frontend pattern
inserts a layer between the user experience and the resources
that the experience calls on. This design allows for customized
user experiences between channels. For example, an app used on a desktop
will have a different screen size, display, and performance limits
than an app used on a mobile device. The BFF pattern allows developers to
create and support one backend type per user interface using the best options for
that interface rather than trying to support a generic backend that works with any interface
but may negatively impact frontend performance. This diagram illustrates a great use case for a
Backend for Frontend application architecture. Suppose a user can access an application via a
mobile app or a web application on a desktop. When applying a BFF pattern, you
develop one backend specifically for the mobile experience and another
backend for the web experience. Each backend knows how to call the
correct services and orchestrate code to optimize the requested channel's experience. The mobile app might display
a more limited subset of data, and the screen sizes will
differ from the web experience. Each backend is a microservice. And instead of having a monolithic app that
checks which channel is needed and then contains all the logic to prepare
the user experience for that channel, you apply microservice architecture
to separate the monolithic backend into distinct services that perform
their specific, necessary tasks. The Strangler pattern helps manage the
refactoring of a monolithic application in stages. The pattern gets its metaphorical name from the
garden phenomenon of a vine that strangles a tree. Think of a web application built using
individual URLs that map functionally to different aspects of a business domain. With the Strangler pattern, you use
the structure of a web application to split an application into
multiple functional domains and replace those domains
with a new microservices-based implementation for one domain at a time. These two aspects form separate applications
that exist side-by-side in the same URL space. Over time, the newly refactored
application replaces the original application until finally, you can
shut off the monolithic application. The Strangler Pattern includes these steps: First, transform. This creates a parallel new site on a cloud
platform or within your existing environment. Next, coexist. This leaves the existing site functional
and live for a specified time. It incrementally redirects
from the current location to the new site for newly implemented functionality. And finally, eliminate. This removes the outdated functionality from
the existing site or stops maintaining that functionality when you redirect
traffic from the original site. Now, a service discovery pattern helps
applications and services discover each other. This pattern is needed because,
in a microservices architecture, service instances change
dynamically due to scaling, upgrades, service failure,
and even service termination. A load balancer could also use this pattern to do health checks and rebalance
traffic on service failures. Other patterns include
the entity and aggregate pattern, which could be used in an e-commerce site, where an order would be an aggregate
of products grouped by a buyer. Another is the adapter pattern. Think of it in the way you think of plug
adapters when traveling to another country. The purpose of adapter patterns
is to help translate relationships between objects that are otherwise incompatible. For example, if you have
integrated with a third-party API. In this video, you learned that microservices enable single-page applications that rely on backing services to
update the page dynamically, Backend for Frontend patterns use microservices to
facilitate different user experiences more easily, you can apply the Strangler pattern to help
break up monolithic apps into microservices, and a service discovery pattern helps
applications and services discover each other.